package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Employee;
import util.DButil;

@WebServlet("/Update")
public class UpdateServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int id = Integer.parseInt(request.getParameter("id"));
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		int age = Integer.parseInt(request.getParameter("age"));
		String type = request.getParameter("type");
		String dapartment = request.getParameter("dapartment");
		int year = Integer.parseInt(request.getParameter("year"));
		String sql = "UPDATE employee SET name = ?, sex = ?, age = ?, "
				+ "dapartment = ?, type = ?, year = ? WHERE id = ?";
		DButil.executeUpdate(sql, new Object[] { name, sex, age, dapartment, type, year, id });
		request.getRequestDispatcher("showEmployee.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
